
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    //JEuler.system.loadJS("data/???.dat");
    JEuler.system.printCaption("75");
    JEuler.system.startTimerCount();
    
    //@url http://en.wikipedia.org/wiki/Pythagorean_triple
    //x=m^2-n^2
    //y=2mn
    //z=m^2+n^2
    //x+y+z = 2m*m+2m*n
    // and gcd(m,n) = 1, m>n
    // and m,n is a odd and a even number
    
    var x2=[];
    for(var i=1; i<=1000; i++) {
        x2[i] = i*i;
    }
    var mList=[], nList=[];
    for(var m=2; m<=1000; m++) {
        for(var n=1; n<=m; n++) {
            if(JEuler.math.gcd(m,n)==1 && (m+n)%2==1) {
                mList.push(m);
                nList.push(n);
            }
        }
    }
    
    var limit = 2000000, sieve=[], L, sum=0;
    for(var i=0; i<=limit; i++) sieve[i] = 0;
    for(var i=0; i<mList.length; i++) {
        L = 2*x2[mList[i]]+2*mList[i]*nList[i];
        for(var j=L; j<=limit; j=j+L) {
            sieve[j] = sieve[j]+1;
        }
    }
    for(var i=0; i<=limit; i++) {
        if(sieve[i]==1) sum++
    }

    JEuler.system.print("SUM=" + sum);
    JEuler.system.printTimerCount();
    
})();
